/**
 * VideoUploadDAO.java
 * Creates a data access object (DAO) for a video data transfer object (DTO).
 * @author Sejung
 */
package com.example.myproject;

import java.util.List;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.util.DAOBase;

public class VideoUploadDAO extends DAOBase{

    static {
        ObjectifyService.register(VideoUploadDTO.class);
    }
    
    /**
     * Saves an VideoUploadDTO to the blobstore.
     * @param dto The video object to be saved.
     */    
    public VideoUploadDTO save(VideoUploadDTO dto) {
        ofy().put(dto);
        return dto;
    }

    /**
     * Retrieves VideoUploadDTOs from the blobstore with matching IDs.
     * @param id Supplied search parameter.
     * @return Returns a key map of VideoUploadDTOs matching id.
     */	
    public VideoUploadDTO findById(Long id) {
    	if(id <= 1L)return null;
        Key<VideoUploadDTO> key = new Key<VideoUploadDTO>(VideoUploadDTO.class, id);
        return ofy().get(key);
    }

    /**
     * Retrieves a list of all VideoUploadDTOs in the blobstore.
     * @return List containing all VideoUploadDTOs in the blobstore.
     */  
	public List<VideoUploadDTO> list() 
	{		
		List<VideoUploadDTO> alist = ofy().query(VideoUploadDTO.class).list();
		return alist;
	}   
	
    /**
     * Retrieves a list of all VideoUploadDTOs in the blobstore whose series
     * matches the supplied string.
     * @param genre Supplied search parameter.
     * @return List containing VideoUploadDTOs with matching series.
     */		
	public List<VideoUploadDTO> listByCaption(String series) 
	{		
		List<VideoUploadDTO> alist = ofy().query(VideoUploadDTO.class).filter("series", series).list();
		return alist; 
	}

    /**
     * Deletes an VidepUploadDTO from the blobstore, specified by id.
     * @param id Supplied id of the VideoUploadDTO to be deleted.
     */
	public void delete(Long id) 
	{
		if(id <= 1L)return;
		VideoUploadDTO video = ofy().query(VideoUploadDTO.class).filter("id ", id).get();
		ofy().delete(video);
	}
	
    /**
     * Deletes a VideoUploadDTO from the blobstore, specified by parentId.
     * @param parentId Supplied parentId of the VideoUploadDTO to be deleted.
     */
	public void deleteByParentId(Long parentId) 
	{	
		if(parentId <= 1L)return;
		VideoUploadDTO video = ofy().query(VideoUploadDTO.class).filter("parentId ", parentId).get();
		ofy().delete(video);
	}
	
}
